<template>
  <div class="photoinfo-container">
    <h3>{{ imageInfo.title }}</h3>
    <p class="subtitle">
      <span>发表时间: {{ imageInfo.add_time | dateFormat}}</span>
      <span>点击 : {{ imageInfo.click }}次</span>
    </p>
    <div class="hr"></div>

    <!-- 缩略图区域 -->
    <vue-preview :slides="list" @close="handleClose"></vue-preview>
    <!-- 图片内容区域 -->
    <div class="content" v-html="imageInfo.content"></div>

    <!-- 放置一个现成的 评论子组件 -->

    <cmt-box :id="id"></cmt-box>
  </div>
</template>
<script>
import { Toast } from 'mint-ui'
import comment from '../subcomponents/comment.vue'
export default {
  data(){
    return {
      id: this.$route.params.id,
      imageInfo: {},
      list: [],  // 缩略图的数组
    }
  },
  methods: {
    getPhotoInfo() {
      // 获取图片的详情
      this.$http.get('api/getimageInfo/' + this.id)
        .then(result => {
          if (result.body.status === 0) {
            this.imageInfo = result.body.message[0]
          } else {
            Toast("获取失败")
          }
        })
    },
    getThumbs(){
      // 获取缩略图
      this.$http.get('api/getthumimages/' + this.id)
        .then(result => {
          if (result.body.status === 0) {
            // 循环每个图片数据 , 补全图片的宽和高
            let _list = result.body.message
            _list.forEach( item => {
              item.msrc = item.src
              item.w = 400
              item.h = 400
            })
            this.list = _list
          } else {
            Toast("获取失败")
          }
        })
    },
    handleClose () {
      // console.log('close event')
    }
  },
  components: { // 注册子组件
    "cmt-box": comment
  },
  created(){
    this.getPhotoInfo()
    this.getThumbs()
  }
}
</script>
<style lang="scss" scoped>
.photoinfo-container{
  padding: 3px;
  h3 {
    color: #26A2FF;
    font-size: 15px;
    text-align: center;
    margin: 15px 0;
  }
  .subtitle {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
  }
  .content {
    font-size: 13px;
    line-height: 30px;
  }
}
</style>
